<?php
if( !defined( '_VALID_MOS' ) && !defined( '_JEXEC' ) ) die( 'Direct Access to '.basename(__FILE__).' is not allowed.' );

  // -- webMS Modification --
  // Check if osCommerce environment is already loaded
  if (defined( '_OSCOMMERCE_LOADED' )) {
    if (!DB_SHARED) {
      // Reconnect to osCommerce Database
      tep_db_connect() or die('Unable to connect to database server!');
    }
    // Load osCommerce Globals for Boxes
    global $category_links, $languages_id, $catID, $catID_array, $current_category_id;
    global $request_type, $lng, $cart, $currencies, $language, $navigation, $breadcrumb;
  } else {
    // Load osCommerce Environment for the First Time
    require('components/'.$option.'/includes/application_top.php');
  }
  $action = $_REQUEST['action'];
  $que_id = $_REQUEST['que_id'];
  $pay_now = $_REQUEST['pay_now'];
//global $que_id, $action, $pay_now;
if($action == 'speed_pay'){
$date = (date (Ymd));
$res = tep_db_query("select * from " . TABLE_SUBSCRIPTION_QUE . " where que_id = '" . $que_id . "'");
$qry = tep_db_fetch_array($res);
$new_prod = "$qry[product_id]";
$new_prod_ex = "-$qry[que_id]";
$next = "$new_prod$new_prod_ex";
$dcheck = tep_db_query("select products_id from " . TABLE_CUSTOMERS_BASKET . " where customers_id = '" . $qry[client_id] . "' and products_id = '$next'");
if (!tep_db_num_rows($dcheck)) {
tep_db_query("INSERT INTO " . TABLE_CUSTOMERS_BASKET . " values ('', '" . $qry[client_id] . "', '" . $next . "', '1', '', '" . $date . "')");
$nord = (date("m/d/Y"));
$ndate = SpeedDate($qry[product_id],$qry[bill_date],$nord);
tep_db_query("INSERT INTO " . TABLE_SUBSCRIPTION . " values ('', '$qry[client_id]', '$qry[product_id]', '$qry[o_order_id]', '$ndate', 'que', '', '')"); 
$id = tep_db_insert_id();
tep_db_query("INSERT INTO " . TABLE_SUBSCRIPTION_QUE . " values ('$id', '$qry[client_id]', '$qry[product_id]', '$qry[o_order_id]', '$ndate', '$qry[status]', '$qry[order_id]', '$qry[pay_date]')"); 
tep_db_query("delete from " . TABLE_SUBSCRIPTION_QUE . " where que_id= '" . $que_id . "'");
//echo $next;
$cart->restore_contents();
tep_redirect(tep_href_link(FILENAME_SHOPPING_CART));
}else{
tep_redirect(tep_href_link(FILENAME_CHECKOUT_SHIPPING));
}

}
?>
